package Servlet;

import DAO.MessageDAO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Objects;

@WebServlet(name= "loginServlet",value = "/loginServlet")
public class LoginServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setCharacterEncoding("UTF-8");
        String UserName= request.getParameter("UserName");
        System.out.println(UserName);
        MessageDAO messageDAO=new MessageDAO();

        JSONArray json= JSONArray.fromObject(messageDAO.loginServlet(UserName));
        if(messageDAO.judgeServlet1(UserName).getUserName()==null){
            JSONObject json1 = new JSONObject();
            json1.accumulate("judge","inExistence");
            json.add(json1);
        }
        System.out.println(json.toString());
        PrintWriter out=response.getWriter();
        out.print(json);
        out.flush();
        out.close();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
}
